package com.adong.crowd.mapper;

import com.adong.crowd.entity.Role;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface AssignMapper {


    /**
     * 根据中间表 inner_admin_role 中的adminId去查询roleId ,然后在本表查询详情
     *
     * @param adminId
     * @return
     */
    @Select("select id, name from t_role where id in(select role_id from inner_admin_role where admin_id =#{adminId})")
    List<Role> selectAssignedRole(Integer adminId);

    @Select("select id,name from t_role where id not in (select role_id from inner_admin_role where admin_id=#{adminId})")
    List<Role> selectUnAssignedRole(Integer adminId);

    @Select("delete from inner_admin_role where admin_id=#{adminId}")
    void deleteOLdRelationship(Integer adminId);

    @Insert("<script> " + "insert into inner_admin_role(admin_id,role_id) values " +
            "<foreach collection='roleIdList' item='roleId' separator=','>" +
            " ( #{adminId}, #{roleId} ) " +
            "</foreach>" +
            "</script>")
    void insertNewRelationship(@Param("adminId") Integer adminId, @Param("roleIdList") List<Integer> roleIdList);

    


}
